<template>
	<view style="min-height: 110rpx;" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<view class="tabbar-container" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
			<block>
				<view class="tabbar-item" v-for="(item,index) in tabbarList"
					:class="[item.centerItem ? ' center-item' : '']" @click="changeItem(item)">
					<view class="item-top">
						<image :src="currentItem==item.id?item.selectIcon:item.icon"></image>
					</view>
					<view class="item-bottom" :class="[currentItem==item.id ? 'item-active' : '']">
						<text>{{item.text}}</text>
					</view>
				</view>
			</block>
		
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			currentPage: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				paddingBottomHeight: 0,
				currentItem: 0,
				tabbarList: [{
					id: 0,
					path: "/pages/index/index",
					icon: "/static/tabbar/home.png",
					selectIcon: "/static/tabbar/home-on.png",
					text: "首页",
					centerItem: false
				}, {
					id: 1,
					path: "/pages/report/submit",
					icon: "/static/tabbar/submit.png",
					selectIcon: "/static/tabbar/submit-on.png",
					text: "随手拍",
					centerItem: true
				}, {
					id: 2,
					path: "/pages/user/index",
					icon: "/static/tabbar/user.png",
					selectIcon: "/static/tabbar/user-on.png",
					text: "我的",
					centerItem: false
				}]

			};
		},
		mounted() {
			this.currentItem = this.currentPage;
			uni.hideTabBar();
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function (res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if(res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 30;
						}
					})
				}
			});
		},
		methods: {
			changeItem(item) {
				let _this = this;
				//_this.currentItem = item.id;  
				uni.switchTab({
					url: item.path
				});
				console.log(item.path)
			}
		}
	}
</script>
<style>
	view {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	.tabbar-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		min-height: 110rpx;
		/* box-shadow: 0 0 5px #999;  */
		box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);
		border-top: 1px;
		display: flex;
		align-items: center;
		/* padding: 5rpx 0; */
		padding-top: 5rpx;
		color: #999999;
		z-index: 200;
		background-color: #fff;
	}

	.tabbar-container .tabbar-item {
		width: 33.33%;
		height: 100rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		text-align: center;
	}

	.tabbar-container .item-active {
		color: #2196F3;
	}

	.tabbar-container .center-item {
		display: block;
		position: relative;
	}

	.tabbar-container .tabbar-item .item-top {
		width: 54rpx;
		height: 54rpx;
		padding: 0rpx;
	}

	.tabbar-container .center-item .item-top {
		flex-shrink: 0;
		width: 100rpx;
		height: 100rpx;
		position: absolute;
		top: -50rpx;
		left: calc(50% - 50rpx);
		border-radius: 50%;
		box-shadow: 0px 3px 20px rgba(0, 0, 0, 0.16);
		/* box-shadow: 0 0 5px #999;  */
		background-color: #ffffff;
		padding: 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tabbar-container .tabbar-item .item-top image {
		width: 80%;
		height: 80%;
	}

	tabbar-container .tabbar-item:nth-child(3) .item-top image {
		background: #ff0000;
	}

	.tabbar-container .tabbar-item .item-bottom {
		font-size: 28rpx;
		width: 100%;
	}

	.tabbar-container .center-item .item-bottom {
		position: absolute;
		bottom: 5rpx;
	}
</style>